<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>${table.comment!}详情</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../../ui/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../ui/layuimini/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" lay-filter="candyForm">
    <input name="id" id="id" style="display: none;"></input>
    <#-- ----------  BEGIN 字段循环遍历  ---------->
    <#list table.fields as field>
    <div class="layui-form-item">
        <label class="layui-form-label required">${field.comment}</label>
        <div class="layui-input-block">
            <input type="text" name="${field.propertyName}" id="${field.propertyName}" lay-verify="required" lay-reqtext="${field.comment}不能为空" placeholder="请输入${field.comment}" value="" class="layui-input">
        </div>
    </div>
    </#list>
    <#------------  END 字段循环遍历  ---------->
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../../ui/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../../ui/layuimini/js/lay-config.js"></script>
<script>
    layui.use(['form','auth'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;
        var id = getQueryString("id");
        var submitType="POST";
        var api="/api<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>";
        if(typeof(id)!="undefined" && id!=null && id.length>=0)
        {
            var settings = {
                "url": api+"/"+id,
                "method": "GET"
            };
            $.ajax(settings).done(function (res) {
                console.log(JSON.stringify(res.data))
                form.val("candyForm", res.data);
            });
            submitType="PUT"
        }
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            console.log(JSON.stringify(data.field));

			var settings = {
			  "url": api,
			  "method": submitType,
              "contentType":"application/json",
			  "data": JSON.stringify(data.field),
			};

			$.ajax(settings).done(function (response) {

			    if(response.code==200)
                {
                    var iframeIndex = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(iframeIndex);
                    parent.reload();
                }
			    else
                {
                    layer.alert(response.msg,{
                        icon: 2
                    });
                }
			}); 
            return false;
        });
    });
</script>
</body>
</html>